/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tuesda.walker.circlerefresh.slice;

import com.tuesda.walker.circlerefresh.CircleRefreshLayout;
import com.tuesda.walker.circlerefresh.LogUtil;
import com.tuesda.walker.circlerefresh.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 示例
 */
public class MainAbilitySlice extends AbilitySlice {

    String[] strs = {
            "The",
            "Canvas",
            "class",
            "holds",
            "the",
            "draw",
            "calls",
            ".5666AA",
            "To",
            "draw",
            "something,",
            "you",
            "need",
            "4 basic",
            "components",
            "Bitmap",
    };

    private CircleRefreshLayout mRefreshLayout;
    private ListContainer mListView;
    private ListAdapter mListAdapter;
    private List<String> list = new ArrayList<>();


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        mRefreshLayout = (CircleRefreshLayout) findComponentById(ResourceTable.Id_refreshLayout);
        mListView = (ListContainer) findComponentById(ResourceTable.Id_list);
        mRefreshLayout.setOnRefreshListener(new CircleRefreshLayout.OnCircleRefreshListener() {
            @Override
            public void completeRefresh() {
            }

            @Override
            public void refreshing() {
            }
        });
        for (int i = 0; i < strs.length; i++) {
            list.add(strs[i]);
        }
        mListAdapter = new ListAdapter(getContext(), list);
        mListView.setItemProvider(mListAdapter);
        mListAdapter.notifyDataChanged();

        Button btnStop= (Button) findComponentById(ResourceTable.Id_btn_stop);
        btnStop.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                mRefreshLayout.finishRefreshing();
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
